package data.datas;

import junit.framework.Assert;

import org.junit.Test;

import stalker.user.User;
import data.content.Content;
import data.content.ContentSentence;

public class CompleteHistoryDatasTest {

  @Test
  public void testDatas() {
    User user = User.createUser("Irvan");
    User user2 = User.createUser("Timi");
    Content content = new ContentSentence("Jahja ganteng tau!");
    
    CompleteHistoryDatas datas = new CompleteHistoryDatas();
    
    Assert.assertTrue("Datas: size fails", datas.size() == 0);
    
    Assert.assertTrue("Datas: isEmpty fails", datas.isEmpty());
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(5).isEmpty());
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(0).isEmpty());
    
    datas.addData(user, content);
    
    Assert.assertTrue("Datas: size fails", datas.size() == 1);
    
    Assert.assertFalse("Datas: isEmpty fails", datas.isEmpty());
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(5).size() == 1);
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(1).size() == 1);
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(0).isEmpty());    
    Assert.assertTrue("Datas: RetrieveLatestData fails", datas.retrieveLatestData().getCreator().equals(user));
    
    datas.addData(user2, content);
    
    Assert.assertTrue("Datas: size fails", datas.size() == 2);
    
    Assert.assertFalse("Datas: isEmpty fails", datas.isEmpty());
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(5).size() == 2);
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(1).size() == 1);
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(0).isEmpty());
    Assert.assertTrue("Datas: RetrieveLatestData fails", datas.retrieveLatestData().getCreator().equals(user2));
    
    Assert.assertTrue("Datas: RetrieveLatestDatas fails", datas.retrieveLatestDatas(3).get(1).equals(datas.retrieveLatestData()));
  }
  
  @Test(expected=AssertionError.class)
  public void testAddNull1() {
    CompleteHistoryDatas datas = new CompleteHistoryDatas();
    datas.addData(User.createUser("Homo"), null);
  }
  
  @Test(expected=AssertionError.class)
  public void testAddNull2() {
    CompleteHistoryDatas datas = new CompleteHistoryDatas();
    datas.addData(null, null);
  }
  
  @Test(expected=AssertionError.class)
  public void testLatestDataOnEmptyDatas()  {
    CompleteHistoryDatas datas = new CompleteHistoryDatas();
    System.out.println(datas.retrieveLatestData());
  }
  
  @Test(expected=AssertionError.class)
  public void testRetrieveNegative() {
    CompleteHistoryDatas datas = new CompleteHistoryDatas();
    System.out.println(datas.retrieveLatestDatas(-1));
  }

}
